//
//  ViewController.m
//  ControlFun
//
//  Created by Justsoso on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIActionSheetDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 需要把self.view 改写成 UIControl类
// 触摸背景的时候，关闭键盘
- (IBAction)backTap:(id)sender
{
    // 两种方法
    // 1.结束编辑
//    [self.view endEditing:YES];
    
    // 2. 取消第一响应者
    [self.nameTextField resignFirstResponder];
    [self.phoneTextField resignFirstResponder];
}


- (IBAction)segementChanged:(UISegmentedControl *)sender
{
    // 分段控件的主要属性:
    // 当前选中项 sender.selectedSegmentIndex
    
    // 1 如果是点开关段
    // 显示开关，隐藏按钮
    // 2 如果是点按钮段
    // 显示按钮，隐藏开关
    
    if(sender.selectedSegmentIndex == 0)
    {
        self.leftSwitch.hidden = NO;
        self.rightSwitch.hidden = NO;
        self.doSomethingBtn.hidden = YES;
    }
    else
    {
        self.leftSwitch.hidden = YES;
        self.rightSwitch.hidden = YES;
        self.doSomethingBtn.hidden = NO;
    }
    
}

- (IBAction)switchChanged:(UISwitch *)sender
{
    // 开关控件的主要属性
    // 开关的当前开关状态
    BOOL open = sender.on;
    
    // 设置状态，并是否带上动画
    [self.leftSwitch setOn:open animated:YES];
    [self.rightSwitch setOn:open animated:YES];
}

- (IBAction)doSomethingBtnPressed:(id)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"你确定么？" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"是的，我确定！" otherButtonTitles:nil];
    [sheet showInView:self.view];
    
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//    NSString *a = [NSString stringWithFormat:@"%@,放轻松，一切都正常运行了",_nameTextField.text];
    if (buttonIndex == actionSheet.destructiveButtonIndex)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"某些事项被执行了" message:[NSString stringWithFormat:@"%@  放轻松，一切都正常运行了",_nameTextField.text] delegate:self cancelButtonTitle:@"欧,耶!" otherButtonTitles: nil];
        [alertView show];
    }
}

- (IBAction)sliderChanged:(UISlider *)sender
{
    // 滑动条的值 value属性
    int value = sender.value;
    // 把滑动条的值显示到Label上
    self.sliderValueLabel.text = [NSString stringWithFormat:@"%i",value];
}
@end
